import request from '@/utils/request';

/**
 * 订单列表初始化
 */
export function orderListInit() {
  return request({
    url:  '/merchant_backend/orders',
    method: 'GET'
  })
}

/**
 * 订单列表查询
 */
export function orderListSearch(date) {
  return request({
    url:  '/merchant_backend/orders',
    method: 'GET',
    params: { order_number: date.order_number, store_id: date.store_id, staff_id: date.staff_id, pay_software: date.pay_software, pay_channel: date.pay_channel, pay_status: date.pay_status, pay_at: { start: date.start, end: date.end }, amount_range: { min: date.min, max: date.max }, qrcode: date.qrcode }
  })
}

/**
 * 订单列表到导出
 */
export function orderListDown(date) {
  return request({
    url:  '/merchant_backend/orders/export',
    responseType: 'zip',
    method: 'GET',
    params: { order_number: date.order_number, store_id: date.store_id, staff_id: date.staff_id, pay_software: date.pay_software, pay_channel: date.pay_channel, pay_status: date.pay_status, pay_at: { start: date.start, end: date.end }, amount_range: { min: date.min, max: date.min }, qrcode: date.qrcode }
  })
}

/**
 * 订单列表到分页
 */
export function orderListPage(page, date) {
  return request({
    url:  '/merchant_backend/orders',
    method: 'GET',
    params: { page, order_number: date.order_number, store_id: date.store_id, staff_id: date.staff_id, pay_software: date.pay_software, pay_channel: date.pay_channel, pay_status: date.pay_status, pay_at: { start: date.start, end: date.end }, amount_range: { min: date.min, max: date.max }, qrcode: date.qrcode }
  })
}

/**
 * 订单列表详情
 */
export function orderList(id) {
  return request({
    url:  '/merchant_backend/orders/' + id,
    method: 'GET'
  })
}

/**
 * 订单列表详情更新状态
 */
export function orderListUpdate(id) {
  return request({
    url:  '/merchant_backend/orders/' + id,
    method: 'PUT'
  })
}

/**
 * 订单列表详情退款申请
 */
export function orderListRefund(id, money, remark) {
  const data = { refund_amount: money, remark }
  return request({
    url:  '/merchant_backend/orders/' + id + '/refund',
    method: 'POST',
    data
  })
}

/**
 * 获取商户名称
 */
export function storesInit() {
  return request({
    url:  '/merchant_backend/stores',
    method: 'GET'
  })
}

/**
 * 获取商户店员
 */
export function stroeUser(id) {
  return request({
    url:  'merchant_backend/stores/' + id + '/staffs',
    method: 'GET'
  })
}

/**
 * 订单数据统计图
 */
export function orderCountInit() {
    return request({
      url:  '/merchant_backend/orders/statistics',
      method: 'GET'
    })
}

/**
 * 订单数据统计图查询
 */
export function orderCountSearch(store_id, start, end) {
    return request({
      url:  '/merchant_backend/orders/statistics',
      method: 'GET',
      params: { store_id, pay_at: {start, end} }
    })
}

/**
 * 退款记录初始化
 */
export function refundInit() {
  return request({
    url:  '/merchant_backend/refund_orders',
    method: 'GET'
  })
}

/**
 * 退款查询
 * @param {Number} date 查询参数
 */
export function refundSearch(date) {
  console.log(date)
  return request({
    url:  '/merchant_backend/refund_orders',
    method: 'GET',
    params: { order_number: date.order_number, refund_at: { start: date.start, end: date.end }, refund_status: date.refund_status, refund_type: date.refund_type }
  })
}
/**
 * 退款分页
 * @param {Number} date 查询参数
 * @param {Number} page 页码
 */
export function refundPage(page, date) {
  return request({
    url:  '/merchant_backend/refund_orders',
    method: 'GET',
    params: { order_number: date.order_number, refund_at: { start: date.start, end: date.end }, refund_status: date.refund_status, refund_type: date.refund_type, page }
  })
}

/**
 * 退款记录-退款详情
 * @param {Number} id 订单id
 */
export function handleRrfundList(id) {
  return request({
    url:  '/merchant_backend/refund_orders/' + id,
    method: 'GET'
  })
}

/**
 * 二维码订单初始化
 */
export function handleCodeInit() {
  return request({
    url:  '/merchant_backend/qrcodes/orders',
    method: 'GET'
  })
}

/**
 * 二维码订单分页
 * @param {Number} page 页码
 * @param {Object} date 查询参数
 */
export function handleCodeChangePage(page, date) {
  return request({
    url:  '/merchant_backend/qrcodes/orders',
    method: 'GET',
    params: { page, order_number: date.order_number, store_id: date.store_id, pay_software: date.pay_software, pay_at:{ start: date.start, end: date.end }}
  })
}

/**
 * 二维码订单查询
 * @param {Object} date 查询参数
 */
export function handleCodeSearch(date) {
  return request({
    url:  '/merchant_backend/qrcodes/orders',
    method: 'GET',
    params: { order_number: date.order_number, store_id: date.store_id, pay_software: date.pay_software, pay_at: { start: date.start, end: date.end } }
  })
}

/**
 * 二维码列表
 */
export function codeListInit() {
  return request({
    url:  '/merchant_backend/qrcodes',
    method: 'GET'
  })
}

/**
 * 收款二维码列表查询
 * @param {Object} date 查询参数
 */
export function handleCodeQrcodeSearch(date) {
  return request({
    url:  '/merchant_backend/qrcodes',
    method: 'GET',
    params: { store_id: date.store_name, created_at: { start: date.start, end: date.end }}
  })
}

/**
 * 收款二维码列表查询
 * @param {Number} page 页码
 * @param {Object} date 查询参数
 */
export function handleCodeQrcodePage(page, date) {
  return request({
    url:  '/merchant_backend/qrcodes',
    method: 'GET',
    params: { page, store_id: date.store_name, created_at: { start: date.start, end: date.end }}
  })
}

/**
 * 二维码导出
 * @param {Object} date 导出参数
 */
export function handleDownCode(date) {
  const data = {
    style: date.style, softwares: date.softwares
  }
  return request({
    url:  '/merchant_backend/qrcodes/' + date.store_id + '/export',
    method: 'POST',
    data
  })
}

/**
 * 二维码批量导出
 * @param {Array} date 导出参数
 */
export function handleDownCodeAll(stores) {
  return request({
    url:  '/merchant_backend/qrcodes/batch_export',
    responseType: 'blob',
    method: 'GET',
    params: { stores }
  })
}